package com.ychs.lawyer.service.impl;

import com.ychs.lawyer.DTO.RoleMenu;
import com.ychs.lawyer.bean.Role;
import com.ychs.lawyer.mapper.RoleMapper;
import com.ychs.lawyer.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/07/25/18:58
 * @Description:
 */
@Service
public class RoleServiceImpl implements RoleService {


    @Autowired
    private RoleMapper roleMapper;
    @Override
    public String getRoleNamekById(Integer id) {
        return roleMapper.getRoleNamekById(id);
    }

    @Override
    public List<Role> getRoles() {
        List<Role> roles = roleMapper.getRoles();
        return roles;
    }

    @Transactional
    @Override
    public Boolean editRole(RoleMenu roleMenu) {
        int i = roleMapper.deleteMenuId(roleMenu);
        int res = roleMapper.editRoleName(roleMenu);
        int i1 = roleMapper.editRole(roleMenu);
        return i1>0?true:false;
    }
    @Transactional
    @Override
    public Boolean addRole(RoleMenu roleMenu) {
        int i = roleMapper.addRole(roleMenu);
        int i1 = roleMapper.addRoleMenu(roleMenu);
        return i1>0&&i>0?true:false;
    }

    @Override
    public List<Role> selectRoleName() {
        return roleMapper.selectRoleName();
    }

    @Transactional
    @Override
    public int deleteRole(Integer roleId) {
        int i = roleMapper.deleteRoleName(roleId);
        int i1 = roleMapper.deleteRoleMenu(roleId);
        return i1;
    }
}
